package cc.idoone.jasperreport.test;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.Map;

import net.sf.jasperreports.engine.JRException;
import net.sf.jasperreports.engine.JasperFillManager;
import net.sf.jasperreports.engine.JasperPrintManager;
import net.sf.jasperreports.engine.data.JRBeanCollectionDataSource;

/**
 * jasper 文档填充保存为 jrprint 文档测试
 * 
 * @author hemj
 * @date 2017年2月14日
 */
public class JasperReportFill {

	public static void main(String[] args) {
		String sourceFileName = "samples/jrtemplates/jasper_report_template.jasper";
		DataBeanList DataBeanList = new DataBeanList();
		ArrayList<DataBean> dataList = DataBeanList.getDataBeanList();

		JRBeanCollectionDataSource beanColDataSource = new JRBeanCollectionDataSource(dataList);

		try {
			Map parameters = new HashMap();
			String jrprint = JasperFillManager.fillReportToFile(sourceFileName, parameters,
					beanColDataSource);
			System.out.println(jrprint);

			if (jrprint != null) {
				JasperPrintManager.printReport(jrprint, true);
			}
		} catch (JRException e) {
			e.printStackTrace();
		}
	}

}
